<?php

namespace Itbbn\ThinkphpModelCreater\lib;


use app\common\util\Env;
use Itbbn\ThinkphpModelCreater\lib\traits\SingleObject;

class Config
{
    use SingleObject;

    /**
     * 数据库表前缀
     * @var string|array|bool|mixed
     */
    public string $prefix = "";

    /**
     * 命名空间
     * @var string
     */
    public string $namespace = 'app\\common\\model';

    /**
     * @var string
     */
    public string $baseNamespace = "base";


    /**
     * 模型目录
     * @var string
     */
    public string $modelDir = "/common/model/";


    /**
     * 模型基类路径,一般是命名空间加斜杠
     * @var string
     */
    public string $baseDir = "base/";

    /**
     * @var bool 调试模式
     */
    public bool $debug = false;

    /**
     * @var string  模型基类
     */
    public string $baseModel = "BaseModel";

    /**
     * @var string 版本号
     */
    public string $version = "";

    public string $connection = "";

    public bool $isThinkPhp = false;
    public string $thinkPhpDbConnection = "";

    public string $author="";


    public function __construct($option = [])
    {
        $this->baseDir = $this->baseNamespace . "/";
    }

    public function setConfig($option)
    {
        $option["path"] ? $this->modelDir = $option["path"] : "";
        $option["root"] ?$this->modelDir = $option["root"] . $option["path"] : $this->modelDir = __DIR__ . "/.." . $this->modelDir;
        $option["namespace"] ? $this->namespace = $option["namespace"] : "";
        $option["baseNamespace"] ? $this->baseNamespace = $option["baseNamespace"] : "";
        $option["prefix"] ? $this->prefix = $option["prefix"] : "";
        $option["baseDir"] ? $this->baseDir = $option["baseDir"] : "";
        $option["debug"] ? $this->debug = $option["debug"] : false;
        $option["baseModel"] ? $this->baseModel = $option["baseModel"] : "";
        $option["version"] ? $this->version = $option["version"] : "";
        $option["connection"] ? $this->connection = $option["connection"] : "";
        $option["isThinkPhp"] ? $this->isThinkPhp = $option["isThinkPhp"] : "";
        $option["thinkPhpDbConnection"] ? $this->thinkPhpDbConnection = $option["thinkPhpDbConnection"] : "";
        $option["author"] ? $this->author = $option["author"] : "";
        if ($this->debug) {
            echo "开启调试模式\n";
        }
    }
}